package com.stx.threeGrup.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by Administrator on 2019/6/3
 */
@Controller
@RequestMapping("/test")
public class TestController {
    //    localhost:8081/webProjectSSM/test/login.do
    @RequestMapping(value = "/testString", produces = "text/html;charset=UTF-8")
    //返回值为json格式用的注解
    public @ResponseBody
    String test() {
        return "这是一个测试用例";
    }

    /**
     * model 和 modelAndView的区别
     * model返回值是地址 modelAndView返回值是对象
     * modeAndView使用 setViewName(forward/redirect 地址)
     * @return
     */
    @RequestMapping("/testFrom")
    public ModelAndView testFrom(ModelAndView mav ) {
        String uname = "asd";
        mav.setViewName("index");
        mav.addObject("name", uname);
        return mav;
//        String uname = "asd";
//        return new ModelAndView("hello", "name", uname);
    }
}
